package cn.lx.resource;

import cn.lx.factory.ElifeSign;
import cn.lx.poi.util.ExcelUtil;


import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/** 测试下载文件
 * Created by lxliuxuan on 2017/2/7.
 */
@Path("/sign")
public class SignResource {

    @GET
    @Path("/get")
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    public Response getAll(@Context  HttpServletResponse rep){

        final List<ElifeSign> signs = new ArrayList<ElifeSign>();
        ElifeSign e = new ElifeSign();
        e.setUserPhone("17011");
        signs.add(e);
        
        StreamingOutput s = new StreamingOutput() {
            public void write(OutputStream output) throws IOException, WebApplicationException {
                ExcelUtil.getInstance().exportObj2ExcelByTemplate(new HashMap<String,String>(),"/excel/test.xls",output, signs, ElifeSign.class, true);
            }
        };


        return Response
                .ok(s)
                .header("Content-disposition","attachment;filename=" + "sign.xls")
                .header("Cache-Control", "no-cache").build();


    }


}



